package com.itheima.controller.shop;

import com.itheima.pojo.Result;
import com.itheima.pojo.Shop;
import com.itheima.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop")
@Slf4j
public class ShopController {
    @Autowired
    private ShopService shopService;

    /**
     * 获取所有好物数据(查)
     *
     * @return
     */
    @GetMapping
    public Result list() {
        List<Shop> shopList = shopService.list();
        return Result.success(shopList);
    }

    /**
     * 添加好物到商品表
     */
    @PostMapping
    public Result addShop(@RequestBody Shop shop) {
        shopService.addShop(shop);
        return Result.success();
    }

    /**
     * 从商品表删除好物
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        shopService.deleteById(id);
        return Result.success();
    }

    /**
     * 根据商家id获取所有的商品
     *
     */
    @GetMapping("/list")
    public Result getListById(@RequestParam Integer uId) {
        List<Shop> list = shopService.getListById(uId);
        return Result.success(list);
    }
    /**
     * 根据商品id获取对应的商品
     *
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Shop shop = shopService.getById(id);
        return Result.success(shop);
    }

    //修改
    @PutMapping
    public Result update(@RequestBody Shop shop) {
        shopService.update(shop);
        return Result.success();
    }

}
